import request from "@/utils/request";
import type { AxiosProgressEvent, AxiosPromise } from "axios";
import type { UploadUserFile } from "element-plus";

/**
 * 上传文件接口
 * @param file 要上传的文件
 * @param onProgress 上传进度回调（可选）
 * @returns 上传结果 Promise
 */
export const uploadFile = (
  file: File,
  onProgress?: (progressEvent: AxiosProgressEvent) => void
): AxiosPromise<any> => {
  const formData = new FormData();
  formData.append("file", file);

  return request({
    url: "/resource/oss/upload", // 你的后端上传路径
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
    onUploadProgress: onProgress,
  });
};
